<%@ page
import="web.Topic"
import="java.util.*"
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta charset="utf-8">
<%
HttpSession s=request.getSession();
String cont=request.getParameter("cont");
String theme=request.getParameter("theme");
int nowpage=1;
int pagesize=0;
String g_size=Topic.getSize();
String g_nowpage=request.getParameter("p");
if(g_nowpage!=null){
	nowpage=Integer.parseInt(g_nowpage);
}
if(g_size!=null){
	int size=Integer.parseInt(g_size);
	if(size%10==0){
		pagesize=size/10;
	}else{
		pagesize=size/10+1;
	}
}

if(cont!=null&&theme!=null&&!cont.equals("")&&!theme.equals("")){
	int uid=(int)s.getAttribute("uid");
	Topic.addTopic(uid, theme);
	int tid=Topic.getMaxTid();
	Topic.reply(uid, tid, cont);
	response.sendRedirect("post.jsp?tid="+tid+"");
}
List<Map> topics=Topic.getTopics(nowpage);
%>


<%if(s.getAttribute("uname")!=null){ %>
	<p>欢迎您！<%=s.getAttribute("uname") %></p>
<%}else{ %>
	<p>欢迎您!<a href="login.jsp">请登录</a></p>
<%} %>
<table>
<%for(Map topic:topics){ %>
	<tr>
	<td><%=topic.get("uname") %></td>
	<td><a href="post.jsp?tid=<%=topic.get("tid") %>"><%=topic.get("theme") %></a></td>
	<td><%=topic.get("create_time") %></td>
	</tr>
<%} %>

</table>
<form action="" method="get">
<%if(s.getAttribute("uname")!=null){ %>
<p>主题<textarea name="theme"></textarea></p>
<p>内容<textarea name="cont"></textarea></p>
<p><input type="submit"></p>
<%} %>
</form>
<p>
第<%=nowpage %>页
<%for(int i=1;i<=pagesize;i++){ %>
	<a href="index.jsp?p=<%=i %>"><%=i %></a>
<%} %>
共<%=pagesize %>页
</p>




